import instance from "@/api/request.js";
import {ElMessage} from "element-plus";

export async function authLogin(credentials) {
    console.log(credentials)
    return await instance
        .post("/auth/login", credentials)
        .then(({code, message, data}) => {
            if (code !== 200) {
                return false;
            }
            ElMessage.success(message || "登录成功！");
            return data;
        })
        .catch((error) => {
            return false;
        });
}

export async function authLogout() {
    return await instance
        .post("/auth/logout")
        .then(({code, message}) => {
            console.log(code, message);
            if (code !== 200) {
                ElMessage.error("登出失败，请稍后重试！");
                return false;
            }
            ElMessage.success(message || "登出成功！");
            return true;
        })
        .catch(() => {
            return false;
        });
}
